package com.foreveredu.erlms.web.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.foreveredu.erlms.domain.Grade;
import com.foreveredu.erlms.service.IExamService;
import com.foreveredu.erlms.web.struts.actionform.GradeActionForm;

public class GradeAction extends AbstractBaseDispatchAction {

	private IExamService examService = null;

	public IExamService getExamService() {
		return examService;
	}

	public void setExamService(IExamService examService) {
		this.examService = examService;
	}
	
	//跳转到前台查询成绩页面
	public ActionForward toQuery(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		return mapping.findForward("toQuery");
	}
	
	//前台查询成绩
	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		GradeActionForm gaf = (GradeActionForm) form;
		if(gaf.getIdCard() == null || "".equals(gaf.getIdCard())){
			request.setAttribute("idCardError", "请输入身份证号！");
			return mapping.findForward("toQuery");
		}
		if (gaf.getTicketNumber() == null || "".equals(gaf.getTicketNumber())) {
			request.setAttribute("ticketNumberError", "请输入准考证号！");
			return mapping.findForward("toQuery");
		}
		Grade grade = examService.findGradeByIDCardAndTicketNumber(gaf.getIdCard(),gaf.getTicketNumber() , examService.getExamOrderOfNow());
		
		request.setAttribute("grade", grade);
		
		return mapping.findForward("toQuery");
	}
}
